package cuongnh.project.japanesediary.vocabulary.ui.wizard.page;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeanProperties;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import cuongnh.project.japanesediary.vocabulary.model.Grammar;
import org.eclipse.swt.widgets.Label;

public class NewGrammarWizardPage extends WizardPage {
	private DataBindingContext m_bindingContext;
	private Text txtGrammar;
	private Text txtVietnameseMeaning;
	private Text txtEnglishMeaning;
	private Text txtJapaneseMeaning;
	private Grammar grammar;
	private Text txtGrammarForm;

	/**
	 * Create the wizard.
	 */
	public NewGrammarWizardPage(Grammar grammar) {
		super("wizardPage");
		setTitle("Wizard Page title");
		setDescription("Wizard Page description");
		this.grammar = grammar;
	}

	/**
	 * Create contents of the wizard.
	 * 
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		container.setLayout(new GridLayout(2, false));

		Group grpGrammar = new Group(container, SWT.NONE);
		grpGrammar.setText("Grammar");
		GridData gd_grpGrammar = new GridData(SWT.FILL, SWT.FILL, false, true,
				2, 1);
		gd_grpGrammar.heightHint = 92;
		grpGrammar.setLayoutData(gd_grpGrammar);
		grpGrammar.setLayout(new GridLayout(1, false));

		txtGrammar = new Text(grpGrammar, SWT.BORDER | SWT.WRAP | SWT.CENTER
				| SWT.MULTI);
		txtGrammar.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
		txtGrammar.setBackground(SWTResourceManager
				.getColor(SWT.COLOR_TITLE_BACKGROUND));
		txtGrammar
				.setFont(SWTResourceManager.getFont("Segoe UI", 18, SWT.BOLD));
		GridData gd_txtGrammar = new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1);
		gd_txtGrammar.heightHint = 81;
		txtGrammar.setLayoutData(gd_txtGrammar);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		Group grpForm = new Group(container, SWT.NONE);
		grpForm.setLayout(new GridLayout(1, false));
		GridData gd_grpForm = new GridData(SWT.FILL, SWT.FILL, false, true, 1,
				1);
		gd_grpForm.widthHint = 363;
		grpForm.setLayoutData(gd_grpForm);
		grpForm.setText("Form");

		txtGrammarForm = new Text(grpForm, SWT.BORDER | SWT.WRAP | SWT.CENTER
				| SWT.MULTI);
		txtGrammarForm.setFont(SWTResourceManager.getFont("Segoe UI", 14,
				SWT.BOLD));
		txtGrammarForm.setForeground(SWTResourceManager
				.getColor(SWT.COLOR_WHITE));
		txtGrammarForm
				.setBackground(SWTResourceManager.getColor(102, 205, 170));
		GridData gd_txtGrammarForm = new GridData(SWT.FILL, SWT.FILL, true,
				true, 1, 1);
		gd_txtGrammarForm.heightHint = 70;
		txtGrammarForm.setLayoutData(gd_txtGrammarForm);

		Group grpMeaning = new Group(container, SWT.NONE);
		grpMeaning.setText("Meaning");
		GridData gd_grpMeaning = new GridData(SWT.FILL, SWT.FILL, true, true,
				1, 1);
		gd_grpMeaning.heightHint = 198;
		grpMeaning.setLayoutData(gd_grpMeaning);
		grpMeaning.setLayout(new GridLayout(1, false));

		TabFolder tabFolder = new TabFolder(grpMeaning, SWT.NONE);
		tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1,
				1));

		TabItem tbtmVietnameseExplaination = new TabItem(tabFolder, SWT.NONE);
		tbtmVietnameseExplaination.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/vietnam.jpg"));
		tbtmVietnameseExplaination.setText("Vietnamese explaination");

		txtVietnameseMeaning = new Text(tabFolder, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmVietnameseExplaination.setControl(txtVietnameseMeaning);

		TabItem tbtmEnglishMeaning = new TabItem(tabFolder, SWT.NONE);
		tbtmEnglishMeaning.setImage(ResourceManager
				.getPluginImage("cuongnh.project.japanesediary.vocabulary",
						"icons/england.jpg"));
		tbtmEnglishMeaning.setText("English explaination");

		txtEnglishMeaning = new Text(tabFolder, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmEnglishMeaning.setControl(txtEnglishMeaning);

		TabItem tbtmJapaneseMeaning = new TabItem(tabFolder, SWT.NONE);
		tbtmJapaneseMeaning.setImage(ResourceManager.getPluginImage(
				"cuongnh.project.japanesediary.vocabulary", "icons/japan.jpg"));
		tbtmJapaneseMeaning.setText("Japanese explaination");

		txtJapaneseMeaning = new Text(tabFolder, SWT.BORDER | SWT.WRAP
				| SWT.V_SCROLL | SWT.MULTI);
		tbtmJapaneseMeaning.setControl(txtJapaneseMeaning);
		m_bindingContext = initDataBindings();
	}

	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeTextTxtGrammarObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtGrammar);
		IObservableValue grammarGrammarObserveValue = BeanProperties.value(
				"grammar").observe(grammar);
		bindingContext.bindValue(observeTextTxtGrammarObserveWidget,
				grammarGrammarObserveValue, null, null);
		//
		IObservableValue observeTextTxtVietnameseExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtVietnameseMeaning);
		IObservableValue vnMeaningGrammarObserveValue = BeanProperties.value(
				"vnMeaning").observe(grammar);
		bindingContext.bindValue(
				observeTextTxtVietnameseExplainationObserveWidget,
				vnMeaningGrammarObserveValue, null, null);
		//
		IObservableValue observeTextTxtEnglishExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtEnglishMeaning);
		IObservableValue enExplainationGrammarObserveValue = BeanProperties
				.value("enMeaning").observe(grammar);
		bindingContext.bindValue(
				observeTextTxtEnglishExplainationObserveWidget,
				enExplainationGrammarObserveValue, null, null);
		//
		IObservableValue observeTextTxtJapaneseExplainationObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtJapaneseMeaning);
		IObservableValue jpExplainationGrammarObserveValue = BeanProperties
				.value("jpMeaning").observe(grammar);
		bindingContext.bindValue(
				observeTextTxtJapaneseExplainationObserveWidget,
				jpExplainationGrammarObserveValue, null, null);
		//
		IObservableValue observeTextTxtGrammarFormObserveWidget = WidgetProperties
				.text(SWT.Modify).observe(txtGrammarForm);
		IObservableValue grammarFormGrammarObserveValue = BeanProperties.value(
				"grammarForm").observe(grammar);
		bindingContext.bindValue(observeTextTxtGrammarFormObserveWidget,
				grammarFormGrammarObserveValue, null, null);
		//
		return bindingContext;
	}
}
